<gm:page title="test" authenticate="false">

<style>
.hidden-obj {
  display: none;
}
</style>

<!--  DATA SOURCES  -->  
<gm:data id="hikesFeed" data="http://www.google.com/base/feeds/snippets/-/hike%20reviews/"/>

<gm:list class="hidden-obj" id="placesList" pagesize="25" data="${hikesFeed}">
  <gm:handleEvent event="repaint" execute="pipe(event);"/>
</gm:list>

<br />

<gm:list id="tmpFeed" data="${tmp}/mainfeed" template="myListPipedTemplate"/>

<input type="button" value="Reload" onClick="pipe();"/> 

<input type="button" value="Delete" onClick="remove();"/> 

<!-- ========================== HTML Templates ============================ -->

<!-- Lista de Trilhas -->  
<gm:template id="myListTemplate">
  <div repeat="true">
    <gm:text ref="atom:title"/> 
  </div>      
</gm:template>  

<gm:template id="myListPipedTemplate">
  <div repeat="true">
   <gm:rating ref="gd:rating"/> <gm:text ref="atom:title"/> 
  </div>   
</gm:template>  


<!-- ================================ JavaScript Code ============================== -->
<script>
  
function remove() {
  var destData = google.mashups.getObjectById('tmpFeed').getData();  
  //var listEntry = google.mashups.getObjectById('tmpFeed').getSelectedEntry();
  
  var i = 0;
  for (i = destData.size() - 1; i >= 0; i--) {  
     destData.removeEntry(destData.entryAt(i));   
  }
}  

function pipe() {
    
  var srcData =  google.mashups.getObjectById('placesList').getData();   
  var destData =  google.mashups.getObjectById('tmpFeed').getData();   

  // Empty Dest
  //alert("dest: " + destData.size());
  var i = 0;
  for (i = destData.size() - 1; i >= 0; i--) {  
     destData.removeEntry(destData.entryAt(i));   
  }
  
  //alert("dest: " + destData.size());  
  //alert("src: " + srcData.size());
  for (i = 0; i < srcData.size(); i++) {
    var entry = srcData.entryAt(i);  
    
    // Create Rating
    ratingGPath = new GPath("g:rating");  
    srcValue = ratingGPath.getValue(entry);  
  
    valueGPath = new GPath("gd:rating/@value"); 
    minGPath = new GPath("gd:rating/@min");
    maxGPath = new GPath("gd:rating/@max");   
    averageGPath = new GPath("gd:rating/@average");     

    valueGPath.setValue(entry, srcValue);  
    averageGPath.setValue(entry, srcValue);
    minGPath.setValue(entry, "1");  
    maxGPath.setValue(entry, "5");    
    
    try { 
     destData.addEntry(entry);    
    } catch(err)   {
      alert("error:" + err.description);
    }
  }
}    
      




</script>
  
  
</gm:page>